using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Backend.JYD.AModel.Models.Mapping
{
    public class CustPhoneMap : EntityTypeConfiguration<CustPhone>
    {
        public CustPhoneMap()
        {
            // Primary Key
            this.HasKey(t => new { t.CustNo, t.Phone, t.IsDefault });

            // Properties
            this.Property(t => t.CustNo)
                .IsRequired()
                .HasMaxLength(20);

            this.Property(t => t.Phone)
                .IsRequired()
                .HasMaxLength(20);

            // Table & Column Mappings
            this.ToTable("CustPhone");
            this.Property(t => t.CustNo).HasColumnName("CustNo");
            this.Property(t => t.Phone).HasColumnName("Phone");
            this.Property(t => t.IsDefault).HasColumnName("IsDefault");
            this.Property(t => t.Status).HasColumnName("Status");
            this.Property(t => t.Type).HasColumnName("Type");
            this.Property(t => t.CreateTime).HasColumnName("CreateTime");
            this.Property(t => t.UpdateTime).HasColumnName("UpdateTime");
            this.Property(t => t.OpId).HasColumnName("OpId");

            // Relationships
            this.HasRequired(t => t.CustBase)
                .WithMany(t => t.CustPhones)
                .HasForeignKey(d => d.CustNo);

        }
    }
}
